//
//  XMResellTypeSelectView.m
//  XMJJ_zml
//
//  Created by 丁浩 on 2025/6/24.
//

#import "XMResellTypeSelectView.h"

@interface XMResellTypeSelectView ()

@property (nonatomic, strong) UIView *contentView;

@end

@implementation XMResellTypeSelectView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self creatUI];
    }
    return self;
}

- (void)creatUI {
    self.backgroundColor = kColorHEXA(0x464646, 0.46);
    [self addSubview:self.contentView];
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, KScaleWidth(24.0), self.width, KScaleWidth(26.0)) font:KFontSize(16.0) textColor:kColorHEX(0x333333) textAlignment:NSTextAlignmentCenter];
    titleLabel.text = @"转卖到";
    [_contentView addSubview:titleLabel];
    
    NSArray *titleArr = @[@"微信", @"私信好友", @"QQ", @"复制链接"];
    NSArray *imgStrArr = @[@"order_share_weichat", @"order_share_friend", @"order_share_QQ", @"order_share_copy"];
    for (int i = 0; i < 4; i ++) {
        UIButton *itemBtn = [UIButton buttonWithType:UIButtonTypeCustom font:KFontSize(14.0) frame:CGRectMake(self.width/4*i, titleLabel.maxY + KScaleWidth(17.0), self.width/4, KScaleWidth(88.0)) title:titleArr[i] titleColor:kColorHEX(0x666666) image:imgStrArr[i]];
        [itemBtn layoutButtonWithEdgeInsetsStyle:CSButtonEdgeInsetsStyleTop ImageTitleSpace:KScaleWidth(8.0)];
        [itemBtn addTarget:self action:@selector(itemSelectAction:) forControlEvents:UIControlEventTouchUpInside];
        [_contentView addSubview:itemBtn];
        itemBtn.tag = 14000 + i;
    }
    
    UIButton *cancelBtn = [UIButton buttonWithType:UIButtonTypeCustom font:KFontSize(16.0) frame:CGRectMake((self.width - KScaleWidth(320.0))/2, _contentView.height - kBottomLayout - KScaleWidth(56.0) - KScaleWidth(44.0), KScaleWidth(320.0), KScaleWidth(44.0)) title:@"取消" titleColor:kColorHEX(0xffffff)];
    cancelBtn.backgroundColor = kColorHEX(0xD7D7D7);
    [cancelBtn setCornerRadius:cancelBtn.height/2];
    [cancelBtn addTarget:self action:@selector(cancelAction:) forControlEvents:UIControlEventTouchUpInside];
    [_contentView addSubview:cancelBtn];
    self.alpha = 0;
}

- (void)show {
    XMWeakSelf;
    [UIView animateWithDuration:.3 animations:^{
        weakSelf.alpha = 1;
        weakSelf.contentView.y = weakSelf.height - weakSelf.contentView.height;
    }];
}

- (void)disMiss {
    XMWeakSelf;
    [UIView animateWithDuration:.3 animations:^{
        weakSelf.alpha = 0;
        weakSelf.contentView.y = weakSelf.height;
    } completion:^(BOOL finished) {
        [weakSelf removeFromSuperview];
    }];
}

- (void)itemSelectAction:(UIButton *)button {
    self.itemSelectBlock ? self.itemSelectBlock(button.tag - 14000) : nil;
    [self disMiss];
}

- (void)cancelAction:(UIButton *)button {
    [self disMiss];
}

#pragma mark - Init
- (UIView *)contentView {
    if (!_contentView) {
        _contentView = [[UIView alloc] initWithFrame:CGRectMake(0, self.height, self.width, KScaleWidth(338.0) + kBottomLayout)];
        [_contentView setPartCornerWithRectCorner:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadius:KScaleWidth(12.0)];
        _contentView.backgroundColor = kColorHEX(0xF5F5F5);
    }
    return _contentView;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
